from typing import Dict
from datetime import datetime

class SourceValidator:
    @staticmethod
    def validate_source(source: Dict) -> bool:
        """
        验证来源的可信度
        :param source: 来源信息字典
        :return: 是否为可信来源
        """
        trusted_venues = {
            'conferences': [
                'NeurIPS', 'ICML', 'ICLR', 'AAAI', 'IJCAI',
                'ACL', 'EMNLP', 'NAACL', 'COLING',
                'CVPR', 'ICCV', 'ECCV',
                'KDD', 'SIGIR', 'WWW'
            ],
            'journals': [
                'Nature', 'Science', 'Cell',
                'IEEE Transactions',
                'ACM Transactions',
                'Journal of Machine Learning Research',
                'Computational Linguistics'
            ]
        }
        
        venue = source.get('venue', '').upper()
        
        # 检查会议名称
        if any(conf.upper() in venue for conf in trusted_venues['conferences']):
            return True
            
        # 检查期刊名称
        if any(journal.upper() in venue for journal in trusted_venues['journals']):
            return True
            
        return False

    @staticmethod
    def check_recency(date_str: str, max_age_days: int = 365) -> bool:
        """
        检查发布日期是否在指定时间范围内
        :param date_str: 日期字符串 (YYYY-MM-DD)
        :param max_age_days: 最大年龄（天数）
        :return: 是否在时间范围内
        """
        try:
            pub_date = datetime.strptime(date_str, '%Y-%m-%d')
            age = (datetime.now() - pub_date).days
            return age <= max_age_days
        except:
            return False
